import './index.scss'
import CONSTANT from '@/common/constants.js'
import http from '@/common/http.js'
import Scroller from 'vux/src/components/scroller/index.vue'
import LoadMore from 'vux/src/components/load-more/index.vue'
export default {
  name: 'findrank',
  components: { Scroller, LoadMore },
  data () {
    return {
      showList: [],
      dayList: [],
      mouthList: [],
      yearList: [],
      pageSize: 10,
      pageNoYear: 0,
      pageNoMouth: 0,
      pageNoDay: 0,
      isA: true,
      isB: false,
      isC: false,
      use_pullup: true,
      pullup_con: {
        content: ' ',
        pullUpHeight: 60,
        height: 40,
        autoRefresh: false,
        downContent: ' ',
        upContent: ' ',
        loadingContent: ' ',
        clsPrefix: 'xs-plugin-pullup-'
      },
      show_loading: false,
      tipText: ''
    }
  },
  mounted () {
    console.log('fasong')
    this.show_loading = true
    this.onScrollBottom()
  },
  methods: {
    onScrollBottom () {
      this.$nextTick(() => {
        this.$refs.scroller.donePullup()
        this.$refs.scroller.reset()
      })
      if (this.isA == true) {
        this.pageNoDay ++
        this.show_loading = true
        http.post(CONSTANT.Day_rank, {pageNo: this.pageNoDay}, (res) => {
          this.show_loading = false
          if (res.code == 200) {
            if (res.errmsg == '没有更多的排名') {
              if (this.pageNoDay > 1) {
                this.pageNoDay--
              }
              this.showList = this.dayList
              this.tipText = '没有更多的排名'
              return
            }
            this.dayList = res.list
            this.showList = this.dayList
          } else {
            this.tipText = '服务器返回出错'
          }
        })
      } else if (this.isB == true) {
        this.show_loading = true
        this.pageNoMouth ++
        http.post(CONSTANT.MONTH_RANK, {pageNo: this.pageNoMouth}, (res) => {
          this.show_loading = false
          console.log(res)
          if (res.code == 200) {
            if (res.errmsg == '没有更多的排名') {
              if (this.pageNoMouth > 1) {
                this.pageNoMouth--
              }
              this.showList = this.mouthList
              this.tipText = '没有更多的排名'
              return
            }
            this.mouthList = res.list
            this.showList = this.mouthList
          } else {
            this.tipText = '服务器返回出错'
          }
        })
      } else if (this.isC == true) {
        this.pageNoYear ++
        this.show_loading = true
        http.post(CONSTANT.YEAR_RANK, {pageNo: this.pageNoYear}, (res) => {
          console.log(res)
          this.show_loading = false
          if (res.code == 200) {
            if (res.errmsg == '没有更多的排名') {
              if (this.pageNoYear > 1) {
                this.pageNoYear--
              }
              this.showList = this.yearList
              this.tipText = '没有更多的排名'
              return
            }
            this.yearList = res.list
            this.showList = this.yearList
          } else {
            this.tipText = '服务器返回出错'
          }
        })
      }
      this.$nextTick(() => {
        this.$refs.scroller.donePullup()
        this.$refs.scroller.reset()
      })
    },
    isAShow () {
      this.$nextTick(() => {
        this.$refs.scroller.donePullup()
        this.$refs.scroller.reset({
          top: 0
        })
      })
      this.isA = true
      this.isB = false
      this.isC = false
      this.tipText = ''
      if (this.pageNoDay == 0) {
        this.onScrollBottom()
      } else {
        this.showList = this.dayList
      }
    },
    isBShow () {
      this.$nextTick(() => {
        this.$refs.scroller.donePullup()
        this.$refs.scroller.reset({
          top: 0
        })
      })
      this.isA = false
      this.isB = true
      this.isC = false
      this.tipText = ''
      if (this.pageNoMouth == 0) {
        this.onScrollBottom()
      } else {
        this.showList = this.mouthList
      }
    },
    isCShow () {
      this.$nextTick(() => {
        this.$refs.scroller.donePullup()
        this.$refs.scroller.reset({
          top: 0
        })
      })
      this.isA = false
      this.isB = false
      this.isC = true
      this.tipText = ''
      if (this.pageNoYear == 0) {
        this.onScrollBottom()
      } else {
        this.showList = this.yearList
      }
    },
    comeBack () {
      window.history.back()
    }
  }
}
